<template>
  <div class="page"></div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from '@/store/index'
import { showLoading } from 'js/utils'
import apis from 'js/apis'
import md5 from 'js-md5'

const router = useRouter()
const store = useStore()

const loading = ref(null)

login()

// 登录
async function login() {
  if (store.userInfo?.id) {
    return router.replace('/')
  }

  const params = {
    account: md5(fromAddress),
    password: fromAddress.slice(-6),
  }

  loading.value = showLoading()
  const { code, data } = await apis.login(params)
  loading.value?.close()

  if (code === 1) {
    store.setUserInfo(data.userinfo)
    router.replace('/')
  }
}
</script>

<style lang="scss" scoped></style>
